home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 033a / dodir.zip / DODIR.BAS < prev    next >
BASIC Source File  |  1991-12-31  |  10KB  |  241 lines

  1. 'syntax:                DODIR  g:\foo\foo1  g:\foo\foo2 etc.
  2. 'author:                Ken Prevo
  3. 'compiler:              BC DODIR /O;  (PDS/BC7 here)
  4. 'Linker:                LINK DODIR,,,PRO7; -- uses crescent library
  5.  
  6. 'WHY SOURCE???  WHY NOT???  There's nothing magic about writing a program;
  7. 'the magic is in the elegance of the design.  Most hide their lack of elegance.
  8. 'I'm at least admitting to and showing everyone my lack...
  9. 'And, if occasionally, I find elegance--I want everybody to know about it. <g>
  10.  
  11. 'This program has no subprogram or functions.  The size of the program and
  12. 'it's limited functionality dictate that's a more than adequate use of
  13. 'structure and gosub is faster and a lot cleaner when the scope of the
  14. 'program is so limited.
  15.  
  16. 'The program will process all the files in a directory using AC150a or such
  17. 'to convert the file from a zip to an arj or whatever
  18. 'the program expects to find GEN\DLPATH but that can be revised by setting
  19. 'the environment variable PCBPATH before activating this program.
  20.  
  21. 'PCBLOG environment variable will send the output to a file rather than the
  22. 'screen if you wish to be able to review the results after an event.
  23.  
  24. DEFINT A-Z
  25.  
  26. ' remarks like '* are for KCC conditional operation--another TOOLKIT program
  27. ' it allows switching from debugging to production code automatically
  28. ' KCC is available as a program or as source from TOOLKIT BBS 219-696-3415
  29.  
  30. ' you don't have PDS, you'll need to make a number of changes at the END #'s
  31. 'These routines are part of the PDQ and/or QuickPak libraries from Crescent
  32. 'most functionality could be replace using HANLIN's shareware libraries
  33. 'or DIR$ function and later use program that changes/checks filesizes that's
  34. 'found in my PCBMAINT.ZIP collection
  35.  
  36. 'all routines from CRESCENT LIB -- substitue from HANLIN LIB if you don't have
  37. DECLARE FUNCTION Exist% (x$)    'check for existance of file
  38. DECLARE FUNCTION FileSize& (x$) 'get the new size of the file being changed
  39.  
  40. 'my goodness, code... you thought we'd never get there, I bet!
  41. IF COMMAND$ = "" THEN
  42.   PRINT "DODIR  [Drv:Path]DIR##"
  43.   PRINT "Where: The paramater passed points to a valid PCB DIR"
  44.   PRINT "SET:   The Following may be set in the environment for use by Program."
  45.   PRINT "       PCBPATH=[BLANK] your pcb master directory--default running from that dir"
  46.   PRINT "       PCBARC=.ZIP or whatever your extension converting from"
  47.   PRINT "       ACCMD=ACNV /J /C -- the parameters you want to pass"
  48.   PRINT "       PCBNEWARC=.ARJ or the extension for the file you're converting from"
  49.   PRINT "       PCBLOG=CONS: Device:/Filename you want to send program output"
  50.   PRINT "       BYPASS=01-31-91 bypass group of files with this in the line"
  51.   PRINT "       TESTING=-1 pretend you're converting to look shelled command and cycling"
  52.   PRINT "Defaults shown.  Program finds the file in the GEN\DLPATH.LST and calls the"
  53.   PRINT "conversion program.  After conversion it changes the file extension and "
  54.   PRINT "adjusts the filesize to reflect the info.  Be sure to clear ENV afterward."
  55.   END 99   'make sure just about any error noting will hit in batch
  56. END IF
  57.  
  58. 'if he got this far, he may have browsed the docs
  59. HomeDir$ = CURDIR$  'save it so we can  get back when we are done
  60.  
  61. 'this notice must remain with this and all dirivative works
  62. x$ = "COPYRIGHT 1991 by Ken Prevo--ALL RIGHTS RESERVED"
  63. PRINT x$
  64.  
  65. Testing% = VAL(ENVIRON$("TESTING"))
  66. PCBPath$ = ENVIRON$("PCBPATH")
  67. IF PCBPath$ = "" THEN PCBPath$ = "GEN\DLPATH.LST"                 '*
  68. '*IF PCBPath$ = "" THEN PCBPath$ = "G:\bbs\GEN\DLPATH.LST"        'testing
  69.  
  70. PCBArchiver$ = ENVIRON$("PCBARC")
  71. IF PCBArchiver$ = "" THEN PCBArchiver$ = ".ZIP"
  72.  
  73. ACCmd$ = ENVIRON$("ACCMD")
  74. IF ACCmd$ = "" THEN ACCmd$ = "ACCMD /J /C"
  75.  
  76. PCBNewArc$ = ENVIRON$("PCBNEWARC")
  77. IF PCBNewArc$ = "" THEN PCBNewArc$ = ".ARJ"
  78. Bypass$ = ENVIRON$("BYPASS")
  79. IF Bypass$ = "" THEN Bypass$ = "01-31-91"'my cd files are indicated so...
  80.  
  81. LogF$ = ENVIRON$("PCBLOG")
  82. IF LogF$ = "" THEN LogF$ = "CONS:"
  83. IF PCBLog$ <> "CONS:" THEN ToScreen% = -1:
  84.  
  85. IF NOT Exist%(PCBPath$) THEN
  86.    PRINT PCBPath$; " not found -- set this value as environment variable PCBPATH"
  87.    END 1
  88. ELSE
  89.   PRINT "Download list: "; PCBPath$
  90. END IF
  91.  
  92. IF LogF$ <> "CONS:" AND NOT Exist%(LogF$) THEN
  93.    PRINT LogF$; "--error--file not found--set environment variable PCBLOG$)"
  94.    END 1
  95. ELSE
  96.    PRINT "Logging to "; LogF$
  97. END IF
  98.  
  99. OPEN PCBPath$ FOR INPUT AS 1
  100. subdir% = 0
  101. DO WHILE NOT EOF(1)
  102.     LINE INPUT #1, x$
  103.     IF LEFT$(x$, 1) <> "@" THEN subdir% = subdir% + 1
  104. LOOP
  105. CLOSE 1
  106. DIM SubDirs$(subdir%)
  107.  
  108. subdir% = subdir% - 1   'base 0 but allow extra for throwaway items$
  109. OPEN PCBPath$ FOR INPUT AS 1
  110. i% = 0
  111. DO WHILE NOT EOF(1)
  112.     LINE INPUT #1, SubDirs$(i%)
  113.     IF LEFT$(SubDirs$(i%), 1) <> "@" THEN
  114.        'subdirs$(i%) = RTRIM$(subdirs$(i%))'in case some putz did an ASCII edit and added spaces--who be so dumb as to do that you ask??? -- Besides you and me!!!
  115.        PRINT "|"; SubDirs$(i%); "|"
  116.        i% = i% + 1
  117.     ELSE
  118.        SubDirs$(i%) = ""
  119.     END IF
  120. LOOP
  121. CLOSE 1
  122.  
  123. OPEN LogF$ FOR OUTPUT AS 3
  124. CmdStr$ = UCASE$(COMMAND$) + " "
  125. PRINT "Command Line: "; COMMAND$
  126. CLPtr% = 1'
  127.  
  128. 'If he got this far, he read and understood the docs--oh, happy day!
  129. '(I hope he didn't forget what to put in the command line...)
  130. DO 'unadvertised feature, I don't use so didn't try/document it
  131.    'process multiple files in single program iteration--caveat emptor
  132.     CLPtr2% = INSTR(CLPtr%, CmdStr$, " ")
  133.     IF CLPtr2% = 0 THEN CLPtr2% = LEN(CmdStr$)
  134.     IF CLPtr% = CLPtr2% THEN EXIT DO
  135.     CurrentDir$ = RTRIM$(MID$(CmdStr$, CLPtr%, CLPtr2% - CLPtr% + 1))   'parse way through command line items
  136.     CLPtr% = CLPtr2%
  137.     IF LEN(CurrentDir$) THEN            'done parsing
  138.         IF NOT Exist%(CurrentDir$) THEN
  139.           PRINT #3, "Missing Directory: "; CurrentDir$
  140.           END 2
  141.         ELSE
  142.           PRINT "Dir: "; CurrentDir$
  143.         END IF
  144.         p% = INSTR(CurrentDir$, ".")
  145.         IF p% = 0 THEN
  146.           CurrentDir$ = CurrentDir$ + "."
  147.           p% = LEN(CurrentDir$)
  148.         END IF
  149.         BakFile$ = CurrentDir$ + "BAK"
  150.         IF Exist%(BakFile$) THEN KILL BakFile$
  151.         NAME CurrentDir$ AS BakFile$
  152.         OPEN BakFile$ FOR INPUT AS 1
  153.         OPEN CurrentDir$ FOR OUTPUT AS 2
  154.         DO WHILE NOT EOF(1)             '!!!!!main file processing loop!!!!!
  155.            LINE INPUT #1, MasterStr$
  156.            IF LEFT$(MasterStr$, 1) > " " THEN 'process as a file
  157.               GOSUB ProcessItem
  158.            ELSE 'pass it through
  159.               PRINT #2, MasterStr$
  160.            END IF
  161.         LOOP
  162.         CLOSE 1, 2
  163.     END IF
  164. LOOP
  165.  
  166. CHDIR HomeDir$
  167. PRINT #3, "Original:"; OldTotFS&
  168. PRINT #3, "New:     "; NewTotFS&
  169. PRINT #3, "Savings: "; OldTotFS& - NewTotFS&
  170. IF FileSize&(PCBPath$) <> FileSize&(CurrentDir$) THEN PRINT #3, "New DIR doesn't match old dir size--check it out"
  171. CLOSE 3
  172. END 0           'normal exit--processing complete
  173.  
  174. ProcessItem:
  175.     IF NOT ToScreen% THEN
  176.        IF ToLeft% THEN
  177.           PRINT CHR$(8);        'destructive backspace
  178.           Ypos% = Ypos% - 1
  179.           IF Ypos% = 0 THEN
  180.             ToLeft% = 0
  181.           END IF
  182.        ELSE                     'print to right
  183.           PRINT ".";
  184.           Ypos% = Ypos% + 1
  185.           IF Ypos% > 78 THEN
  186.             ToLeft% = -1
  187.           END IF
  188.        END IF
  189.     END IF
  190.     Test$ = RTRIM$(LEFT$(MasterStr$, 13))
  191.     TestPtr% = INSTR(Test$, PCBArchiver$) AND INSTR(MasterStr$, Bypass$) = 0
  192.     IF TestPtr% > 0 THEN  'it is the archive fmt we want to convert
  193.         FOR i% = 0 TO subdir%
  194.            x$ = SubDirs$(i%) + Test$
  195.            IF Exist%(x$) THEN 'convert the file
  196.                FS& = FileSize&(x$)
  197.                OldTotFS& = OldTotFS& + FS&
  198.                PRINT #3, x$; FS&; " - ";
  199.                'subdir always has drive in left 2 characters and needs to have the trailing \ removed for chdir
  200.                xx$ = LEFT$(SubDirs$(i%), 2)
  201.                CHDRIVE xx$
  202.                xx$ = LEFT$(SubDirs$(i%), LEN(SubDirs$(i%)) - 1)
  203.                CHDIR xx$
  204.                IF Testing% THEN
  205.                    PRINT ACCmd$; " "; x$;
  206.                    IF Exist%(Test$) THEN PRINT "  -- found for processing" ELSE PRINT " -- Missing FIle"
  207.                ELSE
  208.                    SHELL ACCmd$ + " " + Test$  '*
  209.                    MID$(MasterStr$, INSTR(MasterStr$, "."), 4) = PCBNewArc$
  210.                    x$ = LEFT$(x$, INSTR(x$, ".") - 1) + PCBNewArc$
  211.                    S& = FileSize&(x$)
  212.                    IF DOSError% THEN
  213.                        PRINT #3, "Error: "; WhichError%
  214.                    ELSE
  215.                        PRINT #3, x$; S&
  216.                    END IF
  217.                    NewTotS& = NewTotS& + S& '+ 512 \ 1024
  218.                    NewFS$ = STR$(S&)
  219.                    IF LEN(FS$) < 8 THEN FS$ = SPACE$(8 - LEN(FS$)) + FS$
  220.                    IF S& = -1 THEN  'trouble and big time stuff likely--I chose to abort if not testing
  221.                        '*PRINT #3, "*** not found ***"
  222.                        'the program should abort or whatever as the disk is full or worse
  223.                        'so bailout and let the poor sysop recover as best he can
  224.                        x$ = "DODIR PROGRAM ABORT!!!--combine this dir with .BAK and rebuild/recover."
  225.                        PRINT #2, x$  '*
  226.                        PRINT #3, x$  '*
  227.                        END 1         '*
  228.                    ELSE
  229.                        MID$(MasterStr$, 14, 8) = FS$
  230.                    END IF
  231.                END IF
  232. 'PRINT MasterStr$       'testing/debug
  233.             END IF
  234.         NEXT
  235.     ELSE  'it doesn't contain a convertable file title or is set to bypass
  236.         PRINT #3, "*:"; MasterStr$
  237.     END IF
  238.     PRINT #2, MasterStr$
  239. RETURN
  240.  
  241.